/**
 * Handle changed data.
 *
 * @param {Object} [oldValue] old value
 * @param {Object} [newValue] new value
 * @param {JSEvent} [event] the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"55F168E1-3269-4DDA-B48A-CE2CD82AF5F8"}
 */
function onDataChange_recalcular(oldValue, newValue, event) {
	if (importe_carga_debe < 0)
	{
		importe_carga_debe = importe_carga_debe * -1
	}	    
	if (importe_carga_haber < 0)
	{
		importe_carga_haber = importe_carga_haber * -1
	}	    
	globals.gtotal_debe = 0
	globals.gtotal_haber = 0
	var $cant = databaseManager.getFoundSetCount(foundset)
	for (var i = 1 ; i <= $cant ; i++)
	{
		var $rcd = foundset.getRecord(i)
		if ($rcd.importe_carga_debe != null)
		{
			globals.gtotal_debe  += $rcd.importe_carga_debe.toFixed(2)*1
		} 
		if ($rcd.importe_carga_haber != null)
		{
			globals.gtotal_haber += $rcd.importe_carga_haber.toFixed(2)*1			
		}
	}
	return true
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"983DA291-E463-4EB7-B8C6-CCC4C070B273"}
 */
function onAction_leyenda(event) {
    globals.gform_origen = "limbo_carga_det"
    globals.formEnVentana('limbo_carga_leyendas','LEYENDAS','Leyendas')
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"A4E33369-3A6A-4AD5-B561-1D95A273402E"}
 */
function onAction_borrar(event) {
	controller.deleteRecord()
	onDataChange_recalcular()
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"DB084D1C-57F5-4573-BABA-F49005272816"}
 */
function onShow(firstShow, event) {
	globals.gtotal_debe  = 0
	globals.gtotal_haber = 0
}

/**
 * Handle focus element loosing focus.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"C95EEF08-C77E-4BF9-8830-4BECD93B8A4D"}
 */
function onFocusLost_cuenta(event) {
	elements.cuentas_id.caretPosition = 0
	return true
}
